package gui.admin.tablemodel;

import dao.ProductDao;
import dao.PurchaseDetailsDao;
import dao.SaleDetailsDao;
import entity.Product;
import entity.PurchaseDetails;
import entity.SaleDetails;

import javax.swing.table.DefaultTableModel;
import java.util.List;

public class PurchaseDetailsTableModel extends DefaultTableModel {
    PurchaseDetailsDao purchaseDetailsDao = new PurchaseDetailsDao();
    String[] tableHeaders = new String[]{"商品名称","商品进价","进货数量","价格"};//订单信息表头
    List purchaseDetailsList = null;//用于存放供货单明细的列表
    String[][] purchaseDetailsData = null;
    public PurchaseDetailsTableModel(String purchaseId) throws Exception {
        purchaseDetailsList = purchaseDetailsDao.getAppointPurchaseDeatils(purchaseId);
        ProductDao productDao = new ProductDao();
        purchaseDetailsData = new String[purchaseDetailsList.size()][tableHeaders.length];//创建二位数组
        for (int i = 0; i < purchaseDetailsList.size(); i++) {
            PurchaseDetails purchaseDetails = (PurchaseDetails)purchaseDetailsList.get(i);
            String productId = purchaseDetails.getProductId();
            Product product = productDao.getProductName(productId);
            purchaseDetailsData[i][0] = product.getProductName();//设置表格第i行第1列
            purchaseDetailsData[i][1] = String.valueOf(product.getPurchasePrice());
            purchaseDetailsData[i][2] = String.valueOf(purchaseDetails.getPurchaseNumber());
            purchaseDetailsData[i][3] = String.valueOf((product.getPurchasePrice())*(purchaseDetails.getPurchaseNumber()));
        }
        this.setDataVector(purchaseDetailsData,tableHeaders);
    }
}
